import { serviceStandardSave, standardgetDetail } from '@/api/order'
import { ref } from 'vue'

export default () => {
  // 获取收费标准详情加载
  const getFeeStandardDetailLoading = ref(false)

  // 收费标准详情
  const feeStandardDetail = ref<OrderFeeStandardDetail>({
    delFeeStandardInfoIds: [],
    id: '',
    name: '',
    mobileShow: false,
    feeStandardInfoVos: [],
  })

  /**
   * 获取收费标准详情
   * @param {String} feeStandardId - 收费标准id
   */
  const getFeeStandardDetail = async (feeStandardId: string) => {
    getFeeStandardDetailLoading.value = true
    const res = await standardgetDetail(feeStandardId)
    getFeeStandardDetailLoading.value = false
    feeStandardDetail.value = res.data.data.row
    if (!feeStandardDetail.value.delFeeStandardInfoIds) {
      feeStandardDetail.value.delFeeStandardInfoIds = []
    }
  }

  // 保存收费标准加载
  const updateFeeStandardDetailLoading = ref(false)

  /**
   * 更新收费标准
   */
  const updateFeeStandardDetail = async () => {
    updateFeeStandardDetailLoading.value = true
    const res = await serviceStandardSave(feeStandardDetail.value)
    updateFeeStandardDetailLoading.value = false
    return res.data
  }

  return {
    feeStandardDetail,
    getFeeStandardDetailLoading,
    updateFeeStandardDetailLoading,
    getFeeStandardDetail,
    updateFeeStandardDetail,
  }
}
